package com.wyp168.eduOrder.service.impl;

import com.wyp168.commonutils.ordervo.CourseWebFrontVo;
import com.wyp168.commonutils.ordervo.UCenterMemberOrder;
import com.wyp168.eduOrder.client.EduClient;
import com.wyp168.eduOrder.client.UCenterClient;
import com.wyp168.eduOrder.entity.Order;
import com.wyp168.eduOrder.mapper.OrderMapper;
import com.wyp168.eduOrder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyp168.eduOrder.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author wyp168
 * @since 2022-06-03
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Qualifier("com.wyp168.eduOrder.client.UCenterClient")
    @Autowired
    private UCenterClient centerClient;

    @Autowired
    private EduClient eduClient;

    @Override
    public String createOrders(String courseId, String memberId) {
        System.out.println("!@(#@*(#&*(@&*(3&!(*#*!@883!&*(!*@(321");
        //通过服务调用根据用户id来获取用户信息
        UCenterMemberOrder userInfoOrder = centerClient.getUserInfoOrder(memberId);
        //通过服务调用根据课程id来获取课程信息
        CourseWebFrontVo courseInfoOrder = eduClient.getCourseInfoOrder(courseId);

        //创建一个Order对象，想order对象中设置需要的数据
        Order order=  new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId); //课程id
        order.setCourseTitle(courseInfoOrder.getTitle());
        order.setCourseCover(courseInfoOrder.getCover());
        order.setTeacherName(courseInfoOrder.getTeacherName());
        order.setTotalFee(courseInfoOrder.getPrice());
        order.setMemberId(memberId);
        order.setMobile(userInfoOrder.getMobile());
        order.setNickname(userInfoOrder.getNickname());
        order.setStatus(0);  //订单状态（0：未支付 1：已支付）
        order.setPayType(1);  //支付类型 ，微信1
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
